<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #container {

            clear: both;
            width: 677px;
            height: 254px;
            border: 1px solid red;
            margin: 100px auto;
        }

        #container .text_input {
            margin-top: 16px;
            margin-left: 32px;
            float: left;
            overflow: scroll;
            box-sizing: border-box;
            width: 274px;
            height: 188px;
            border: 1px solid lightseagreen;
        }

        #container .show {
            float: left;
            margin-top: 16px;
            width: 80px;
            height: 54px;
            border: 1px solid red;
        }

        #container .show .show_top {

            width: 78px;
            height: 20px;
            background: #f7f7f7;
            border: 1px solid #ccc;
            border-radius: 4px;
            line-height: 20px;
            text-align: center;
            color: #ccc;
            font-size: 12px;
        }

        #container .show .box1 {
            display: none;
            margin-top: 2px;
            background: yellow;
            text-align: center;
            line-height: 30px;
            width: 78px;
            height: 30px;
        }

        #container .txt_out {
            margin-top: 16px;
            float: left;
            box-sizing: border-box;
            width: 274px;
            height: 188px;
            border: 1px solid #000;
            overflow: auto;
        }

        /* #container .show .p1 {
            display: block;
        } */
    </style>
</head>

<body>
    <div id="container">
        <textarea class="text_input"></textarea>
        <div class="show">
            <button class="show_top">把文字右移</button>
            <div class="box1"><span id="out_number">0</span>/<span id="input_number">0</span></div>
        </div>
        <div class="txt_out">
        </div>
    </div>

    <script>
        // 获取输入的盒子
        let text_input = $(".text_input")[0];
        // 获取文字右移按钮
        let show_top = $(".show_top")[0];

        // 获取输出的文字数目
        let out_number = $("#out_number")[0];
        // 获取输入的文字数目
        let input_number = $("#input_number")[0];
        // 获取输出的盒子
        let txt_out = $(".txt_out")[0];
        let box1 = $("div")[2];
     
        var index = 0;
        // 右移按钮点击事件
        show_top.onclick = function () {
            // 判断文本域是否为空
            if (text_input.value.length == 0) {
                console.log("文本域内容不能为空");
            } else {
                // 显示box1盒子
            
                box1.style.display = "block";
                input_number.innerHTML = text_input.value.length;
                var text_content = text_input.value;
                if (txt_out.innerHTML == "") {
                    out_number.innerHTML = text_input.value.length;
                } else {
                    // console.log("你好");
                    setInterval(function () {
                        out_number.innerHTML = text_content.substring(index++, text_content.length).length;

                    }, 100);
                    // 获取文本域的内容
                    setInterval(function () {
                        txt_out.innerText = text_content.substring(0, index++);
                        text_input.value = text_content.substring(index++, text_content.length);
                    }, 100);

                }
            }

        }

        function $(select) {
            return document.querySelectorAll(select);

        }

    </script>
</body>

</html>